package com.holly.unit.config.modular.controller;

import com.holly.unit.config.api.pojo.ConfigInitRequest;
import com.holly.unit.config.modular.param.SysConfigParam;
import com.holly.unit.config.modular.service.SysConfigService;
import com.holly.unit.core.pojo.request.BaseRequest;
import com.holly.unit.core.pojo.response.ResponseData;
import com.holly.unit.core.pojo.response.SuccessResponseData;
import com.holly.unit.scanner.api.annotation.ApiResource;
import com.holly.unit.scanner.api.annotation.GetResource;
import com.holly.unit.scanner.api.annotation.PostResource;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;


/**
 * 参数配置控制器
 *
 * @author holly
 * @date 2020/4/13 22:46
 */
@RestController
@ApiResource(name = "参数配置控制器")
@Api(tags = "参数配置控制器")
public class SysConfigController {

    @Resource
    private SysConfigService sysConfigService;

    /**
     * 添加系统参数配置
     *
     * @author holly
     * @date 2020/4/14 11:11
     */
    @ApiOperation(value = "添加系统参数配置" ,notes = "添加系统参数配置")
    @PostResource(name = "添加系统参数配置", path = "/sysConfig/add")
    public ResponseData add(@RequestBody @Validated(BaseRequest.add.class) SysConfigParam sysConfigParam) {
        sysConfigService.add(sysConfigParam);
        return new SuccessResponseData();
    }

    /**
     * 删除系统参数配置
     *
     * @author holly
     * @date 2020/4/14 11:11
     */
    @ApiOperation(value = "删除系统参数配置" ,notes = "删除系统参数配置")
    @PostResource(name = "删除系统参数配置", path = "/sysConfig/delete")
    public ResponseData delete(@RequestBody @Validated(SysConfigParam.delete.class) SysConfigParam sysConfigParam) {
        sysConfigService.del(sysConfigParam);
        return new SuccessResponseData();
    }

    /**
     * 编辑系统参数配置
     *
     * @author holly
     * @date 2020/4/14 11:11
     */
    @ApiOperation(value = "编辑系统参数配置" ,notes = "编辑系统参数配置")
    @PostResource(name = "编辑系统参数配置", path = "/sysConfig/edit")
    public ResponseData edit(@RequestBody @Validated(SysConfigParam.edit.class) SysConfigParam sysConfigParam) {
        sysConfigService.edit(sysConfigParam);
        return new SuccessResponseData();
    }

    /**
     * 查看系统参数配置
     *
     * @author holly
     * @date 2020/4/14 11:12
     */
    @ApiOperation(value = "查看系统参数配置" ,notes = "查看系统参数配置")
    @GetResource(name = "查看系统参数配置", path = "/sysConfig/detail")
    public ResponseData detail(@Validated(SysConfigParam.detail.class) SysConfigParam sysConfigParam) {
        return new SuccessResponseData(sysConfigService.detail(sysConfigParam));
    }


    /**
     * 分页查询配置列表
     *
     * @author holly
     * @date 2020/4/14 11:10
     */
    @ApiOperation(value = "分页查询配置列表" ,notes = "分页查询配置列表")
    @GetResource(name = "分页查询配置列表", path = "/sysConfig/page")
    public ResponseData page(SysConfigParam sysConfigParam) {
        return new SuccessResponseData(sysConfigService.findPage(sysConfigParam));
    }

    /**
     * 系统参数配置列表
     *
     * @author holly
     * @date 2020/4/14 11:10
     */
    @ApiOperation(value = "系统参数配置列表" ,notes = "系统参数配置列表")
    @GetResource(name = "系统参数配置列表", path = "/sysConfig/list")
    public ResponseData list(SysConfigParam sysConfigParam) {
        return new SuccessResponseData(sysConfigService.findList(sysConfigParam));
    }

    /**
     * 获取系统配置是否初始化的标志
     *
     * @author holly
     * @date 2021/7/8 17:20
     */
    @ApiOperation(value = "获取系统配置是否初始化的标志" ,notes = "获取系统配置是否初始化的标志")
    @GetResource(name = "获取系统配置是否初始化的标志", path = "/sysConfig/getInitConfigFlag", requiredPermission = false)
    public ResponseData getInitConfigFlag() {
        return new SuccessResponseData(sysConfigService.getInitConfigFlag());
    }

    /**
     * 初始化系统配置参数，用在系统第一次登录时
     *
     * @author holly
     * @date 2021/7/8 16:36
     */
    @ApiOperation(value = "初始化系统配置参数" ,notes = "初始化系统配置参数")
    @PostResource(name = "初始化系统配置参数，用在系统第一次登录时", path = "/sysConfig/initConfig", requiredPermission = false)
    public ResponseData initConfig(@RequestBody ConfigInitRequest configInitRequest) {
        sysConfigService.initConfig(configInitRequest);
        return new SuccessResponseData();
    }

    /**
     * 获取需要初始化的配置列表
     *
     * @author holly
     * @date 2021/7/8 16:36
     */
    @ApiOperation(value = "获取需要初始化的配置列表" ,notes = "")
    @GetResource(name = "获取需要初始化的配置列表", path = "/sysConfig/getInitConfigList")
    public ResponseData getInitConfigList() {
        return new SuccessResponseData(sysConfigService.getInitConfigs());
    }

    /**
     * 获取需要初始化的配置列表
     *
     * @author holly
     * @date 2021/7/8 16:36
     */
    @ApiOperation(value = "获取初始密码" ,notes = "")
    @GetResource(name = "获取初始密码", path = "/sysConfig/getByConfigCode")
    public ResponseData getByConfigCode(String configCode) {
        return new SuccessResponseData(sysConfigService.getByConfigCode(configCode));
    }

}


